<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Account\Controller;
use App\Models\Module;
use App\Services\ModuleService;
use Illuminate\Http\Request;


class ModuleController extends Controller
{



    public function index(ModuleService $moduleService)
    {
        //获取所有模块信息,installed为数据库中存在，则true
        $modules = $moduleService->all();
        return view('module.index', compact('modules'));
    }

    //依赖注入ModuleService服务
    public function install($name, ModuleService $moduleService)
    {
        $module = $moduleService->find($name);
        Module::create($module);
        return back()->with('success', '模块安装成功');
    }

    public function uninstall(Module $module)
    {

        $module->delete();
        // return back()->with('success', '成功删除');
        return response()->json(['message', '删除成功']);
    }
}
